package com.sjzd.server.controller;


import com.sjzd.server.pojo.Department;
import com.sjzd.server.pojo.RespBean;
import com.sjzd.server.service.IDepartmentService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author sjzd
 * @since 2021-02-21
 */
@RestController
@RequestMapping("/sys/basic/dept")
@Api("部门controller")
public class DepartmentController {

    @Autowired
    private IDepartmentService departmentService;

    @ApiOperation("添加部门")
    @PostMapping("/")
    public RespBean addDept(@RequestBody Department department) {
        if (null == department) {
            return RespBean.error("入参为空，操作失败");
        }
        return departmentService.addDept(department);
    }

    @ApiOperation("删除部门")
    @DeleteMapping("/{id}")
    public RespBean delDept(@PathVariable int id) {
        return departmentService.delDeptById(id);
    }

    @ApiOperation("获取所有部门列表")
    @GetMapping("/")
    public List<Department> getAllDepts() {
        return departmentService.getAllDepts();
    }

}
